home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
SNIP9_91.ARJ
/
QBSORT.C
< prev
next >
Wrap
Text File
|
1991-09-07
|
2KB
|
62 lines
/******************************************************************/
/* */
/* Quick single-pass bubble sort */
/* (OK, I know it's an oxymoron, but it's fast enough */
/* for small arrays and it's _VERY_ small!) */
/* */
/******************************************************************/
enum LOGICAL {ERROR = -1, FALSE, TRUE};
qbsort(char *str_array[], int number)
{
int backup = FALSE, i = 0, j = 1, last = 0;
void _pascal swapem(char *[], int, int);
while ((i + 1) < number)
{
if (strcmp(str_array[i], str_array[j]) <= 0)
{
/* In order continue... */
if (backup)
{
/* If we were reversing, quit */
i = j = last;
++j;
backup = FALSE;
}
else
{ /* Go on to next entries */
++i;
++j;
}
last = 0; /* Flag top of sort */
}
else
{
/* Out of order - backup and swap */
backup = TRUE;
if (!last) /* Remember where we were */
last = j;
if (i == 0)
{
/* At bottom, swap and goto top*/
swapem(str_array, i, j);
i = j = last;
++j;
backup = last = 0;
}
else swapem(str_array, i--, j--);
}
}
}
static void _pascal swapem(char *str_array[], int last, int now)
{
register char *s_temp;
s_temp = str_array[last];
str_array[last] = str_array[now];
str_array[now] = s_temp;
}